iOS tips

文件 ARC && MRC 设置

ARC 项目中使用 MRC 文件 使用

1
-fno-objc-arc

MRC 项目中使用 ARC 文件 使用

1
-fobjc-arc

具体设置如下所示:

performSelector的警告忽略

1
2
3
4
5
6
7
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"") \
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

如果没有返回结果,可以直接按如下方式调用:

1
2
3
SuppressPerformSelectorLeakWarning(
[_target performSelector:_action withObject:self]
);

如果要返回结果,可以按如下方式调用:

1
2
3
4
id result;
SuppressPerformSelectorLeakWarning(
result = [_target performSelector:_action withObject:self]
);

地图初始化系统弹框提示(是否允许获取用户坐标)一闪而过

1
2
3
CLLocationManager 不能使用局部变量或者弱引用,需要使用全局变量如下:

self.locationManager = [[CLLocationManager alloc] init];